<!DOCTYPE html>
<!--
This is a starter template page. Use this page to start your new project from
scratch. This page gets rid of all links and provides the needed markup only.
-->
<html>
<head>
    <meta charset="UTF-8">
    <title>省考试院自学考试考务管理系统</title>
    <meta content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no' name='viewport'>
    <!--导入基础依赖css文件-->
    <link href="../../static/css/basic.css" rel="stylesheet" type="text/css" />
    <!--导入自己的 css -->
    <link href="../../static/css/bmbk/create-exam.css" rel="stylesheet" type="text/css" />
</head>
<body class="skin-blue sidebar-mini">
<div class="wrapper">
    <!-- Main Header -->
    <header class="main-header">

        <!-- Logo -->
        <a href="/" class="logo">
            <!-- mini logo for sidebar mini 50x50 pixels -->
            <span class="logo-mini"><b>考务</b></span>
            <!-- logo for regular state and mobile devices -->
            <span class="logo-lg"><b>自学考试 </b>考务管理</span>
        </a>

        <!-- Header Navbar -->
        <nav class="navbar navbar-static-top" role="navigation">
            <!-- 打开左侧导航栏按钮 -->
            <a href="#" class="sidebar-toggle" data-toggle="offcanvas" role="button">
                <span class="sr-only">左侧导航栏</span>
            </a>
            <!-- 头部：右侧导航栏 -->
            <div class="navbar-custom-menu">
                <ul class="nav navbar-nav">
                    <!-- 消息提示菜单 -->
                    <li class="dropdown notifications-menu">
                        <!-- Menu toggle button -->
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <span class="glyphicon glyphicon-comment"></span>
                            <span class="label label-warning">10</span>
                        </a>
                        <ul class="dropdown-menu">
                            <li class="header">你有 10 条信息待处理</li>
                            <li>
                                <!-- Inner Menu: contains the notifications -->
                                <ul class="menu">
                                    <li><!-- start notification 如果有多条 可用 v-for -->
                                        <a href="#">
                                            <i class="fa fa-users text-aqua"></i> 5 条白名单申请待处理
                                        </a>
                                    </li><!-- end notification -->
                                </ul>
                            </li>
                            <li class="footer"><a href="#">查看全部</a></li>
                        </ul>
                    </li>
                    <!-- User Account Menu -->
                    <li class="dropdown user user-menu">
                        <!-- Menu Toggle Button -->
                        <a href="#" class="dropdown-toggle" data-toggle="dropdown">
                            <!-- The user image in the navbar-->
                            <img src="../../static/dist/img/user2-160x160.jpg" class="user-image" alt="User Image"/>
                            <!-- hidden-xs hides the username on small devices so only the image appears. -->
                            <span class="hidden-xs">FF</span>
                        </a>
                        <ul class="dropdown-menu">
                            <!-- The user image in the menu -->
                            <li class="user-header">
                                <img src="../../static/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image" />
                                <p>
                                    FF
                                    <small>四川大学考务</small>
                                </p>
                            </li>
                            <!-- Menu Footer-->
                            <li class="user-footer">
                                <div class="pull-left">
                                    <a href="#" class="btn btn-default btn-flat">个人</a>
                                </div>
                                <div class="pull-right">
                                    <a href="#" class="btn btn-default btn-flat">登出</a>
                                </div>
                            </li>
                        </ul>
                    </li>
                </ul>
            </div>
        </nav>
    </header>

    <!-- 左侧边栏 -->
    <aside class="main-sidebar">
        <!-- sidebar: style can be found in sidebar.less -->
        <section class="sidebar">
            <!-- 用户面板 -->
            <div class="user-panel">
                <div class="pull-left image">
                    <img src="../../static/dist/img/user2-160x160.jpg" class="img-circle" alt="User Image" />
                </div>
                <div class="pull-left info">
                    <p>FF</p>
                    <!-- 用户角色 -->
                    <a href="#"><i class="fa fa-circle text-success"></i> 考务</a>
                </div>
            </div>

            <!-- 搜索框 -->
            <form action="#" method="get" class="sidebar-form">
                <div class="input-group">
                    <input type="text" name="q" class="form-control" placeholder="搜索..."/>
              <span class="input-group-btn">
                <button type='submit' name='search' id='search-btn' class="btn btn-flat"><i class="glyphicon glyphicon-search"></i></button>
              </span>
                </div>
            </form>
            <!-- /.search form -->

            <!-- 菜单栏 -->
            <ul class="sidebar-menu">
                <li class="header"></li>
                <!--a标签使用示例-->
                <li><a href="/"><span>首页</span></a></li>
                <li class="active"><a href="../bmbk/"><span>报名报考</span></a></li>
                <li><a href="#"><i class='glyphicon glyphicon-link'> </i><span>带图标链接示例</span></a></li>
                <li class="treeview">
                    <a href="#"><span>多级链接示例</span> <i class="fa fa-angle-left pull-right"></i></a>
                    <ul class="treeview-menu">
                        <li><a href="#">二级链接</a></li>
                        <li><a href="#">二级链接</a></li>
                    </ul>
                </li>
            </ul><!-- /.sidebar-menu -->
        </section>
        <!-- /.sidebar -->
    </aside>

    <!-- 页面内容 -->
    <div class="content-wrapper">
        <!-- Content Header (Page header) -->
        <section class="content-header">
            <h1>
                考试列表
                <small>考试查询</small>
            </h1>
            <ol class="breadcrumb">
                <li><a href="#">报名报考</a></li>
                <li class="active">考试列表</li>
            </ol>
        </section>

        <!-- Main content -->
        <section class="content">
            <!-- 我们的页面内容放这里 -->
            <div id="show_exam">

                <div class="box">
                    <div class="box-header with-border">
                        <input  placeholder="请输入搜索内容" class="col-xs-2"  v-model="searchVal" />
                        <button @click="search()" type="button" class="btn btn-default btn-sm" style="margin-left: 10px">搜索</button>
                    </div>
                    <div class="box-body">

                        <div class="row">
                            <table class="table table-bordered" id="list_table">
                                <tbody>
                                <tr>
                                    <th style="width: 10%; text-align: center;">考试类型</th>
                                    <th style="width: 10%; text-align: center;">考次</th>
                                    <th style="width: 10%; text-align: center">操作</th>
                                </tr>
                                <tr v-for="(item, index) in currentPageData" :key="index" v-show="list">
                                    <td style="width: 10%; text-align: center;"><span>{{examTypelist[item.type_name]}}</span></td>
                                    <td style="width: 10%; text-align: center;">{{item.kc_code}}</td>
                                    <td style="width: 10%; text-align: center;">
                                        <div class="btn-group">
                                            <button @click="findExam(index)" type="button" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
                                        </div>
                                    </td>
                                </tr>
                                <tr v-for="(item, index) in searchData" :key="index" v-show="search_result_issue">
                                    <td style="width: 5%; text-align: center;"><span>{{examTypelist[item.type_name]}}</span></td>
                                    <td style="width: 20%; text-align: center;">{{item.kc_code}}</td>
                                    <td style="width: 10%; text-align: center;">
                                        <div class="btn-group">
                                            <button @click="findExam(index)" type="button" class="btn btn-default"><span class="glyphicon glyphicon-search"></span></button>
                                        </div>
                                    </td>
                                </tr>
                                </tbody>
                            </table>
                        </div>

                        <div clsss="col-sm-7" style="align-items: center;text-align: center" v-show="list">
                            <button @click="prevPage()">
                                上一页
                            </button>
                            <span>第{{currentPage}}页/共{{totalPage}}页</span>
                            <button @click="nextPage()">
                                下一页
                            </button>
                        </div>

                        <div class="exam_button" v-show="searchState>0">
                            当前查询：{{exam}}
                        </div>
                    </div>
                </div>
            </div><!-- /.box-body -->
        </section><!-- /.content -->
    </div><!-- /.content-wrapper -->

    <!-- Main Footer -->
    <footer class="main-footer">
        <div style="display: flex; justify-content: center; align-items: center;">
            <div><strong>Copyright &copy; 2020 <a href="#">省考试院自学考试考务管理</a>.</strong> All rights reserved.</div>
        </div>
    </footer>
</div><!-- ./wrapper -->

<!-- 基础 js 文件 -->
<!-- jQuery 2.1.4 -->
<script src="../../static/plugins/jQuery/jQuery-2.1.4.min.js"></script>
<!-- popper.min.js -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.7/umd/popper.min.js" integrity="sha384-UO2eT0CpHqdSJQ6hJty5KVphtPhzWj9WO1clHTMGa3JDZwrnQq4sF86dIHNDz0W1" crossorigin="anonymous"></script>
<!-- Bootstrap 3.3.2 JS -->
<script src="../../static/bootstrap/js/bootstrap.min.js" type="text/javascript"></script>
<!-- AdminLTE App -->
<script src="../../static/dist/js/app.min.js" type="text/javascript"></script>
<!-- vuejs -->
<script src="../../static/js/vue.js"></script>
<!-- axios：前后端数据交互 -->
<script src="https://unpkg.com/axios/dist/axios.min.js"></script>

<script>
    let show_exam = new Vue({
        el: '#show_exam',
        data: {
            exam:{},
            searchState:-1,
            searchVal:'',
            list:true,
            search_result_issue:false,
            searchData:[],
            examList: [{type_name: null, kc_code: null}],
            totalPage: 1, // 统共页数，默认为1
            currentPage: 1, //当前页数 ，默认为1
            pageSize: 10, // 每页显示数量
            currentPageData: [], //当前页显示内容
            showModel:false,
            examTypelist: ['','统考', '省考', '英语听说', '毕业论文', '实践性环节']
        },
        created:function(){
            this.getList();
        },
        mounted:function(){
            this.getList();
        },
        methods: {
            getList:function(){
                let that = this;
                axios.post('/exam/allExam')
                        .then(function(response){
                            Vue.nextTick(function(){
                                that.examList = response.data;
                                console.log(response.data);
                                that.totalPage = Math.ceil(that.examList.length / that.pageSize);
                                // 计算得0时设置为1
                                that.totalPage = this.totalPage == 0 ? 1 : that.totalPage;
                                that.setCurrentPageData();
                            })
                        })
                        .catch(function(error){
                            console.log(error)
                        })

            },
            setCurrentPageData:function(){
                let begin = (this.currentPage - 1) * this.pageSize;
                let end = this.currentPage * this.pageSize;
                this.currentPageData = this.examList.slice(
                        begin,
                        end
                );
            },
            search: function () {
                let that = this;
                let searchVal = that.searchVal;
                let examList = that.examList;
                if(searchVal == undefined || searchVal == '' || searchVal== null){
                    alert("搜索内容不能为空！");
                }else {
                    that.list = false;
                    that.search_result_issue = true;
                    that.searchList = [];//搜索后的数据
                    examList.map(function(item) {
                        if (item.kc_code.search(searchVal) != -1) {
                            that.searchList.push(item);
                        }
                    });
                }

            },
            prevPage() {
                console.log(this.currentPage);
                if (this.currentPage == 1) return;

                this.currentPage--;
                this.setCurrentPageData();

            },
            // 下一页
            nextPage() {
                if (this.currentPage == this.totalPage)return ;

                this.currentPage++;
                this.setCurrentPageData();

            },
            findExam: function (index) {
                let that = this;
                if(index > -1){
                    axios.post('/exam/findExam',
                            {
                                kc_code: that.examList[index].kc_code,
                                type_name: that.examList[index].type_name
                            })
                            .then(function (response) {
                                console.log(response);
                                that.searchState = 1;
                                that.exam = response.data;
                                alert("查询考试成功！");
                            })
                            .catch(function (error) {
                                console.log(error);
                                that.searchState = -1;
                                alert("查询考试失败！");
                            });
                }else{
                    alert("当前考试不存在！");
                }
            }
        }
    })
</script>
</body>
</html>